<?php


namespace app\Server;


use Webman\Push\Api;

class PushServer
{

    protected $app_key;

    protected $auth ;

    protected $api;


    public function __construct()
    {
        $this->app_key = config("plugin.webman.push.app.app_key");
        $this->auth = "/plugin/webman/push/auth";
        $this->api = new Api('http://127.0.0.1:3232', config('plugin.webman.push.app.app_key'),
            config('plugin.webman.push.app.app_secret'));
    }


    public function send($channel,$function,$data=[],$msg = "操作成功",$code = 200,$dump = false)
    {
        $send_data =  [
            "function"=>$function,
            "data"=>$data,
            "message"=>$msg,
            "code" =>$code
        ];
        if ($dump){
            dump($send_data);
        }
        $this->api->trigger('private-user-'.$channel,"message",$send_data);
    }


}